package cn.edu.neusoft.demo.hospital2.Dao;

import cn.edu.neusoft.demo.hospital2.pojo.DoctorWork;
import cn.edu.neusoft.demo.hospital2.pojo.FullDoctorWork;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DoctorWorkDao extends BaseMapper<DoctorWork> {
    // 查询医生出诊信息
    List<DoctorWork> getDoctorWorkList(DoctorWork doctorWork);
    // 根据医生 ID 查询排班信息
    List<DoctorWork> getDoctorWorkByDoctorId(String docId);
    //根据医生id和日期删除
    @Delete("delete from doctor_work where doc_id=#{docId} and day=#{day}")
    int deleteByDocIdAndDay(@Param("docId") String docId, @Param("day") String day);

    // ... existing code ...
    /**
     * 使用 Wrapper 删除记录（自定义实现）
     */
    int deleteUsingWrapper(@Param("ew") Wrapper<DoctorWork> wrapper);

    // 更新可挂号数量
    int updateCountLeft(DoctorWork doctorWork);

    @Select("SELECT	d.*, dw.fee_id,dw.DAY,dw.amwork,dw.pmwork FROM doctor d left join	doctor_work dw on d.doc_id = dw.doc_id where dw.day='${day}'")
    List<FullDoctorWork> selectAllInfo(@Param("day")String day);

    @Update("update doctor_work set count_left=count_left-1 where count_left>0 and day='${day}' and doc_id='${docId}'")
    int updateCountLeftById(DoctorWork dw);

    @Update("update doctor_work set count_left=count_left+1 where  day='${day}' and doc_id='${docId}'")
    int updateCountLeftById2(DoctorWork dw);

    DoctorWork getDoctorWorkByDayAndDocId(@Param("day") String day, @Param("docId") String docId);
}
